#include<iostream>
#include<string>
#include<unistd.h>
#include<pthread.h>
using std::cout;
using std::endl;

void threadPrint(const void* threadName,const pthread_t tid)
{
    cout<<"The threadname::"<<threadName<<"tid::"<<tid<<"pid::"<<getpid()<<endl;
}

void* tid1Fun(void* agrc)
{
    char* threadName=(char*)agrc;
    int cnt=5;
    while(true)
    {
        threadPrint(threadName,pthread_self());
        sleep(2);
        cnt--;
        if(cnt==0)
        {
            pthread_exit((void*)123);
        }
    }
}
int main()
{
    pthread_t tid1;
    pthread_create(&tid1,nullptr,tid1Fun,(void*)"I am tid1!");
    
    pthread_cancel(tid1);
    cout<<"Main thread has cancel tid1!"<<endl;

    void* ret=nullptr;
    pthread_join(tid1,&ret);
    cout<<"Main thread join success!"<<endl;
    sleep(2);

    cout<<"thread exit result::"<<(long long)ret<<endl;

    return 0;
}
